package com.wangxiang.shop.product.data;

import cn.hutool.core.util.NumberUtil;
import com.wangxiang.common.utils.DataEntity;
import com.wangxiang.common.utils.R;
import com.wangxiang.shop.product.service.ShopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("product/data")
public class DataController {
    @Autowired
    private ShopTypeService service;


    //基础分类
    @RequestMapping("basetype")
    public R baseTypeData(){
        List<DataEntity> list = service.shopTypeData();
        return R.ok().put("list",list);
    }
    //二级分类
    @RequestMapping("twotypedata")
    public R twoShopData(){
        List<DataEntity> list = service.twoTypeData();
        return R.ok().put("list",list);
    }
    //三级分类
    @RequestMapping("threetypedata")
    public R treeShopData(){
        List<DataEntity> list = service.treeTypeData();
        return R.ok().put("list",list);
    }
    @RequestMapping("baseware")
    public R baseWare(){
        List<DataEntity> list = service.wareTotalData();
        int total = 0;
        for (DataEntity dataEntity : list) {
            total=dataEntity.getValue()+total;
        }

        for (DataEntity dataEntity : list) {
            double div = NumberUtil.div(dataEntity.getValue(), total);
            dataEntity.setProportion(Integer.valueOf((int) (div*100)));
            dataEntity.setStyle("height:"+Integer.valueOf((int) (div*100))+"%");
        }

        return R.ok().put("list",list).put("total",total);
    }
    @RequestMapping("shopThreeWare")
    public R shopWare(){
        List<DataEntity> list = service.shopThreeWare();
        return R.ok().put("list",list);
    }


}
